#include "timewheel.hpp"
#include <iostream>
#include <unistd.h>
class TestTimeWheel
{
public:
    TestTimeWheel()
    {
        std::cout << "构造" << '\n';
    }
    ~TestTimeWheel()
    {
        std::cout << "析构" << '\n';
    }
};

void Del(TestTimeWheel* ptr)
{
    delete ptr;
}
void TestFunc()
{
    TimeWheel time_wheel(60);
    TestTimeWheel* ptr = new TestTimeWheel();
    int id = 1000;
    time_wheel.AddTask(id, 5, std::bind(Del, ptr));
    for(int i = 0; i < 5; i++) {
        sleep(1);
        time_wheel.RunTimerTask();//向后移动秒针

        time_wheel.TimerRefresh(id);//刷新定时任务
        std::cout << "刷新了一下定时任务, 重新需要5s后才会销毁\n";
    }
    // time_wheel.TimerCancel(id);
    // int i = 0;
    while(1) {
        sleep(1);
        // if(i == 4)
        //    time_wheel.TimerRefresh(id);//刷新定时任务
        // ++i;
        std::cout << "-------------------\n";
        time_wheel.RunTimerTask();//向后移动秒针
    }

}
int main()
{
    TestFunc();
    return 0;
}